package www.way2inbox.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.way2sms.way2inbox.R;

import java.text.SimpleDateFormat;
import java.util.List;

import www.way2inbox.data.simsfetch;
import www.way2inbox.data.smsfetch;

/**
 * Created by sys1031 on 13/12/14.
 */
public class SimsListAdapter extends ArrayAdapter {

    private Activity activity;

    private List<simsfetch> items;
    private int row;
    private simsfetch objBean;
    //	public ImageLoader imageLoader;
    final String OLD_FORMAT = "yyyy/MM/dd HH:mm";
    final String NEW_FORMAT = "MMM d,\nh:mm a";
    String newDateString,oldDateString;
    SimpleDateFormat sdf;


    public SimsListAdapter(Activity act, int row, List<simsfetch> items) {
        super(act, row, items);

        this.activity = act;
        this.row = row;
        this.items = items;
//		imageLoader=new ImageLoader(activity.getApplicationContext());

    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View view = convertView;
//		imageLoader = new ImageLoader(activity.getApplicationContext());

        final ViewHolder holder;
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(row, null);

            holder = new ViewHolder();
            holder.Ph_name = (TextView) view.findViewById(R.id.sim_no);
            holder.Ph_id = (TextView) view.findViewById(R.id.sim_id);
            holder.Ph_imei = (TextView) view.findViewById(R.id.sim_imei);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }


        if ((items == null) || ((position + 1) > items.size()))
            return view;


        objBean = items.get(position);


//		if (holder.servecount != null && null != objBean.get_Served()) {
//			holder.servecount.setText(objBean.get_Served());
//
//			Log.d("servecount", objBean.get_Served().toString());
//
//	}



        if (holder.Ph_name != null  ) {
            if(objBean.getSim_no()!=null) {
                holder.Ph_name.setText(objBean.getSim_no());
                holder.Ph_id.setText(objBean.getSim_id());
                holder.Ph_imei.setText(objBean.getSim_imei());
            }else{
                holder.Ph_name.setText(R.string.Multi_sim_error);
            }
        }



        return view;



    }

    public class ViewHolder {

        public TextView Ph_name,Ph_id,Ph_imei;



    }
}
